<style lang="less">
    @import "./main.less";
</style>
<template>
    <div class="main" :class="{'main-hide-text': shrink}">

        <div class="sidebar-menu-con" :style="{width: shrink?'60px':'200px', overflow: shrink ? 'visible' : 'auto'}">
            <scroll-bar ref="scrollBar">
                <shrinkable-menu
                        :shrink="shrink"
                        @on-change="handleSubmenuChange"
                        :theme="menuTheme"
                        :before-push="beforePush"
                        :open-names="openedSubmenuArr"
                        :menu-list="menuList">
                    <div slot="top" class="logo-con" style="text-align: center">
                        <span v-show="!shrink">办公系统</span>
                        <span v-show="shrink">A</span>
                    </div>
                </shrinkable-menu>
            </scroll-bar>
            <!--<Button :style="{transform: 'rotateZ(' + (this.shrink ? '-90' : '0') + 'deg)'}" type="text"-->
            <!--@click="toggleClick">-->
            <!--<Icon type="navicon" size="32"></Icon>-->
            <!--</Button>-->
        </div>
        <div class="main-header-con"
             :style="{left:shrink?'60px':'200px',width:shrink?'calc(100% - 60px)':'calc(100% - 200px)'}">
            <div class="main-header" style="background: rgb(73, 80, 96)">
                <div class="navicon-con">
                    <div style="height: 48px;line-height: 48px; margin-left: 12px;">

                        <Button style="color:#fff"
                                :style="{transform: 'rotateZ(' + (this.shrink ? '-90' : '0') + 'deg)'}"
                                type="text" @click="toggleClick">
                            <Icon type="navicon" size="30"></Icon>
                        </Button>
                    </div>
                </div>
                <div class="header-avator-con">
                    <!--<message-center :data="messages"></message-center>-->
                    <div class="user-dropdown-menu-con">
                        <Row type="flex" justify="end" align="middle" class="user-dropdown-innercon">
                            <Dropdown transfer trigger="click" @on-click="handleClickUserDropdown">
                                <a href="javascript:void(0)">
                                    <span class="main-user-name">{{ userName }}</span>
                                    <Avatar :src="avatorPath" style="background: #619fe7;margin-left: 10px;"></Avatar>

                                    <!--<Icon type="arrow-down-b"></Icon>-->
                                </a>
                                <DropdownMenu slot="list">
                                    <DropdownItem name="ownSpace">个人中心</DropdownItem>
                                    <DropdownItem name="loginout" divided>退出登录</DropdownItem>
                                </DropdownMenu>
                            </Dropdown>
                        </Row>
                    </div>
                </div>
            </div>
            <div class="tags-con">
                <tags-page-opened :pageTagsList="pageTagsList"></tags-page-opened>
            </div>
        </div>
        <div ref="pageArea" class="single-page-con" :style="{left: shrink?'60px':'200px'}">
            <div class="single-page">
                <router-view></router-view>
            </div>
        </div>

    </div>
</template>
<script>
  import shrinkableMenu from './main-components/shrinkable-menu/shrinkable-menu.vue';
  import util from '@/libs/util.js';
  import scrollBar from '@/views/my-components/scroll-bar/vue-scroller-bars';
  import tagsPageOpened from './main-components/tags-page-opened.vue';
  import messageCenter from './my-components/message-center/message-center.vue'

  export default {
    components: {
      shrinkableMenu,
      scrollBar,
      tagsPageOpened,
      messageCenter
    },
    data () {
      return {
        shrink: false,
        mesCount:10,
        userName: '',
        isFullScreen: false,
        openedSubmenuArr: this.$store.state.app.openedSubmenuArr,
        messages:[
          {
            sender:'admin',
            title:'请及时更新系统',
            sendDate:'5分钟以前',
            isRead:false
          },
          {
            sender:'admin',
            title:'请及时更新系统1',
            sendDate:'5分钟以前',
            isRead:false
          },
          {
            sender:'admin',
            title:'请及时更新系统2',
            sendDate:'5分钟以前',
            isRead:true
          },
        ]
      };
    },
    computed: {
      menuList () {
        return this.$store.state.app.menuList;
      },
      avatorPath () {
        return localStorage.avatorImgPath;
      },
      lang () {
        return this.$store.state.app.lang;
      },
      menuTheme () {
        return this.$store.state.app.menuTheme;
      },
      pageTagsList () {
        return this.$store.state.app.pageOpenedList; // 打开的页面的页面对象
      }
    },
    methods: {
      init () {
        this.userName = this.$auth.user().name;
        this.$store.commit('setMessageCount', 3);
        this.$Message.config({
          duration: 2
        });
      },
      toggleClick () {
        this.shrink = !this.shrink;
      },
      handleClickUserDropdown (name) {
        if (name === 'ownSpace') {
          util.openNewPage(this, 'ownspace_index');
          this.$router.push({
            name: 'ownspace_index'
          });
        } else if (name === 'loginout') {
          this.$store.commit('logout', this);
          this.$auth.logout({
            redirect: '/login',
            makeRequest: false
          });
        } else if (name === 'adminArea') {
          this.$router.push({
            name: 'system-setting_index'
          });
        } else if (name === 'orgMgt') {
          this.$router.push({
            name: 'org-mgt_index'
          });
        }
      },
      handleSubmenuChange (val) {
      },
      beforePush (name) {
        return true;
      },
      scrollBarResize () {
        this.$refs.scrollBar.resize();
        this.$store.commit('setPageAreaHeight', this.$refs.pageArea.offsetHeight);
      }
    },
    watch: {
      '$route' (to) {
        localStorage.currentPageName = to.name;
      },
      lang () {
      },
      openedSubmenuArr () {
        setTimeout(() => {
          this.scrollBarResize();
        }, 300);
      }
    },
    mounted () {
      this.init();
      window.addEventListener('resize', this.scrollBarResize);
      this.$store.commit('setPageAreaHeight', this.$refs.pageArea.offsetHeight);
      if (this.$auth.check()) {
        this.$store.commit('setAccessControl', this.$auth.user().access);
        this.$store.commit('updateMenulist');
      }
    },
    created () {
      this.$store.commit('setOpenedList');
    },
    dispatch () {
      window.removeEventListener('resize', this.scrollBarResize);
    }
  };
</script>
